package com.kiki.recommendations.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.kiki.recommendations.domain.RecommendationsVo;
import com.kiki.song.mapper.SongMapper;
import com.kiki.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.kiki.recommendations.mapper.RecommendationsMapper;
import com.kiki.recommendations.domain.Recommendations;
import com.kiki.recommendations.service.IRecommendationsService;

/**
 * 推荐结果Service业务层处理
 * 
 * @author 林志毅
 * @date 2025-04-25
 */
@Service
public class RecommendationsServiceImpl implements IRecommendationsService 
{
    @Autowired
    private RecommendationsMapper recommendationsMapper;

    @Autowired
    private SongMapper songMapper;

    @Autowired
    private SysUserMapper userMapper;

    /**
     * 查询推荐结果
     * 
     * @param recId 推荐结果主键
     * @return 推荐结果
     */
    @Override
    public Recommendations selectRecommendationsByRecId(Long recId)
    {
        return recommendationsMapper.selectRecommendationsByRecId(recId);
    }

    /**
     * 查询推荐结果列表
     * 
     * @param recommendations 推荐结果
     * @return 推荐结果
     */
    @Override
    public List<RecommendationsVo> selectRecommendationsList(Recommendations recommendations)
    {
        List<RecommendationsVo> RecommendationsVoList = new ArrayList<>();
        for (Recommendations recommendations1 : recommendationsMapper.selectRecommendationsList(recommendations)) {
            RecommendationsVo recommendationsVo = new RecommendationsVo();
            recommendationsVo.setRecId(recommendations1.getRecId());
            recommendationsVo.setRecommendTime(recommendations1.getRecommendTime());
            //获取歌名
            recommendationsVo.setSongName(songMapper.getSongNameBySongId(recommendations1.getSongId()));
            //获取用户名
            recommendationsVo.setUserName(userMapper.selectUserNameByUserId(recommendations1.getUserId()));
            recommendationsVo.setType(recommendations1.getType());
            RecommendationsVoList.add(recommendationsVo);

        }
        return RecommendationsVoList;
    }

    /**
     * 新增推荐结果
     * 
     * @param recommendations 推荐结果
     * @return 结果
     */
    @Override
    public int insertRecommendations(Recommendations recommendations)
    {
        return recommendationsMapper.insertRecommendations(recommendations);
    }

    /**
     * 修改推荐结果
     * 
     * @param recommendations 推荐结果
     * @return 结果
     */
    @Override
    public int updateRecommendations(Recommendations recommendations)
    {
        return recommendationsMapper.updateRecommendations(recommendations);
    }

    /**
     * 批量删除推荐结果
     * 
     * @param recIds 需要删除的推荐结果主键
     * @return 结果
     */
    @Override
    public int deleteRecommendationsByRecIds(Long[] recIds)
    {
        return recommendationsMapper.deleteRecommendationsByRecIds(recIds);
    }

    /**
     * 删除推荐结果信息
     * 
     * @param recId 推荐结果主键
     * @return 结果
     */
    @Override
    public int deleteRecommendationsByRecId(Long recId)
    {
        return recommendationsMapper.deleteRecommendationsByRecId(recId);
    }
}
